var t = require("../../../@babel/runtime/helpers/slicedToArray"),
  e = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  a = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  r = require("../../../utils/index").tools.common.getHeaderHeight;

function n() {
  return i.apply(this, arguments)
}

function i() {
  return (i = a(e().mark((function a() {
    var r, n, i, o, u, c, l, h, d, p, f, g = arguments;
    return e().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          if (r = g.length > 0 && void 0 !== g[0] ? g[0] : 1, this.page = r || 1, 1 !== r && this.setData({
              loading: !0
            }), e.prev = 2, n = {
              pageNum: this.page,
              pageSize: 15
            }, this.data.last_id && 1 !== (null == n ? void 0 : n.pageNum) && (n.last_id = this.data.last_id), 0 != this.data.last_id || 1 === n.pageNum) {
            e.next = 6;
            break
          }
          return e.abrupt("return");
        case 6:
          return e.next = 8, $.request["GET/business/combine/order/pageList"]({
            isInvoicing:0
          });
        case 8:
          return i = e.sent, o = t(i, 1), u = o[0], console.log(u), c = u.data, l = c.data,
            l.map((item) => {
              item.checked = false;
            }),
            h = c.last_id, e.next = 16, s(l);
        case 16:
          if (d = e.sent, 1 !== r || 0 !== d.length) {
            e.next = 19;
            break
          }
          return e.abrupt("return", void this.setData({
            noData: !0,
            list: []
          }));
        case 19:
          if (d.length < 15 && h <= 0 ? this.setData({
              hasMore: !0
            }) : this.setData({
              hasMore: !1
            }), 1 !== r) {
            e.next = 21;
            break
          }
          return e.abrupt("return", void this.setData({
            list: d,
            noData: !1,
            last_id: h
          }));
        case 21:
          p = this.data.list.length, f = d.reduce((function (t, e, a) {
            return t["list[".concat(a + p, "]")] = e, t
          }), {
            noData: !1,
            last_id: h
          }), this.setData(f);
        case 23:
          return e.prev = 23, this.setData({
            loading: !1
          }), e.finish(23);
        case 26:
        case "end":
          return e.stop()
      }
    }), a, this, [
      [2, , 23, 26]
    ])
  })))).apply(this, arguments)
}

function s(t) {
  return o.apply(this, arguments)
}

function o() {
  return (o = a(e().mark((function t(a) {
    return e().wrap((function (t) {
      for (;;) switch (t.prev = t.next) {
        case 0:
          return t.abrupt("return", (a.forEach((function (t) {
            2 == t.check && (2 != t.use_type ? t.titleTag = [{
              title: 1 == t.status ? "空闲中" : "工作中",
              color: "#fff",
              bgColor: "rgba(4, 181, 120, 1)"
            }] : t.titleTag = [{
              title: "已通过",
              color: "#fff",
              bgColor: "rgba(4, 181, 120, 1)"
            }]), 1 == t.check && (t.titleTag = [{
              title: "审核中",
              color: "#fff",
              bgColor: "#0092ff"
            }]), 0 == t.check && (t.titleTag = [{
              title: "未通过",
              color: "#fff",
              bgColor: "rgba(204, 58, 53, 1)"
            }])
          })), a));
        case 1:
        case "end":
          return t.stop()
      }
    }), t)
  })))).apply(this, arguments)
}
Page({
  data: {
    list: [],
    loading: !1,
    calcHeight: r("14rpx"),
    noData: !1,
    hasMore: !1,
    last_id: "",
    type: "",
    name: "",
    type: '',
    id: ""
  },
  chooseOrder(e) {
    console.log(e)
    var list = this.data.list
    list.map((item) => {
      if (e.currentTarget.dataset.item.id == item.id) {
        item.checked = !item.checked
      }
    })
    this.setData({
      list: list
    })
  },
  chooseTitle() {
    wx.navigateTo({
      url: '/subpackage/invoice/title-list/index?type=1',
    })
  },
  onSubmit() {
    var selectList = [];
    this.data.list.map((item) => {
      if (item.checked) {
        selectList.push(item.id)
      }
    })
    if (selectList.length == 0) {
      wx.showToast({
        icon: "none",
        title: '请选择订单'
      })
    } else {
      $.request['POST/business/invoice/record/add']({
        orderIdList: selectList,
        invoiceHeaderId: this.data.id
      }).then(res => {
        res = res[0]
        if (res.code == 20002) {
          wx.showToast({
            icon: "none",
            title: '开票成功'
          })
          setTimeout(() => {
            wx.navigateBack()
          }, 500);
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg
          })
        }
      })
    }
    console.log(selectList)
  },
  onLoad: function (t) {
    this.getTitle()
    t.type && this.setData({
      type: t.type
    }), n.call(this, 1)
  },
  getTitle(){
    var that = this;
    $.request['GET/business/invoice/header/pageList']().then(res => {
      res = res[0]
      res.data.data.map((item) => {
        if (item.isDefault == 1) {
          that.setData({
            name: item.name,
            type: item.type,
            id: item.id
          })
        }
      })
    })
  },
  onPullDownRefresh: function () {
    n.call(this, 1).finally((function () {
      wx.stopPullDownRefresh()
    }))
  },
  onReachBottom: function () {
    this.data.hasMore || this.data.noData || n.call(this, this.page + 1)
  },
  onShow: function () {
    var t = this;
    n.call(this, 1)
    return a(e().mark((function a() {
      var r;
      return e().wrap((function (e) {
        switch (e.prev = e.next) {
          case 0:
            "publish" == (null == (r = $.router.getParams()) ? void 0 : r["page-type"]) && n.call(t, 1);
          case 2:
          case "end":
            return e.stop()
        }
      }), a)
    })))()
  },
  onToPublish: function () {
    $.router.push("/subpackage/invoice/add-title/index")
  },
  onButtonTap: function (r) {
    var i = this,
      s = r.currentTarget.dataset,
      o = s.type,
      u = s.item;
    o && (2 == o ? $.router.push("/subpackage/invoice/add-title/index", {
      uu_id: u.id
    }) : 3 == o ? $.router.push("/subpackage/device/fast-modify/index", {
      uu_id: u.uu
    }) : $.jxAlert({
      mode: "confirm",
      hideClose: !0,
      title: "温馨提示",
      content: "确定删除吗?",
      confirmText: "确定",
      cancelText: "取消"
    }).then(a(e().mark((function a() {
      var r, s;
      return e().wrap((function (e) {
        for (;;) switch (e.prev = e.next) {
          case 0:
            return e.next = 2, $.request["DELETE/business/wechat/contact/del/" + u.id]();
          case 2:
            r = e.sent, s = t(r, 1), 20002 == s[0].code && ($.msg("删除成功"), n.call(i, 1));
          case 6:
          case "end":
            return e.stop()
        }
      }), a)
    })))))
  },
  choosePerson(e) {
    $.router.back({
      params: {
        label: "汽车吊",
        "select-type": this.data.type,
        value: [{
          id: e.currentTarget.dataset.item.contactUserPhone,
          name: e.currentTarget.dataset.item.contactUserName,
          phone: e.currentTarget.dataset.item.contactUserPhone,
        }]
      }
    });
  },

  onMachine: function (t) {
    var e = t.detail.row.uu;
    $.router.back({
      params: {
        uuid: e
      }
    })
  }
});